package com.maxsalad.uc.pojo;

import com.maxsalad.common.message.IMessage;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * Created by 2014-400 on 2016-01-26.
 */
public class ResponseResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private IMessage messages;
    private String code;
    private Boolean suc = true;
    private String message;
    private Object result;

    public ResponseResult() {

    }

    public ResponseResult(IMessage messages) {
        this.messages = messages;
    }

    public ResponseResult(Object result) {
        this.result = result;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String errorCode) {
        this.code = errorCode;
    }

    public void setSucMessage() {
        this.suc = true;
        setMessage("S00001");
    }

    public void setSucMessage(String messageKey, Object... params) {
        this.suc = true;
        setMessage(messageKey, params);
    }

    public void setFaultMessage(String messageKey, Object... params) {
        this.suc = false;
        if (StringUtils.isNotBlank(messageKey)) {
            setMessage(messageKey, params);
        } else {
            setMessage("E00001", params);
        }

    }

    public void mergeMessage(String message) {
        this.message = this.message + message;
    }

    public void setMessage(String messageKey, Object... params) {
        this.message = messages.getMessage(messageKey, params);
        this.code = messageKey;

    }

    public String getMessage() {
        return message;
    }


    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.suc = true;
        this.result = result;
    }

    public void setFaultResult(Object result) {
        this.suc = false;
        this.result = result;
    }

    public Boolean getSuc() {
        return suc;
    }
}
